<template>
  <div>
    <el-row>
      <h1 align="left">{{table_name}}</h1>
    </el-row>
    <hr>
    <el-table
      :data="table_fields"
      style="width: 100%">
      <el-table-column
        prop="name"
        label="列名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="cons"
        label="属性">
      </el-table-column>
    </el-table>
    <hr>
    <el-table
      :data="table_constraint"
      style="width: 100%">
      <el-table-column
        prop="content"
        label="约束">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  name: 'SqlContent',
  created() {
    this.fresh_this(this.$route.params.table);
  },
  data() {
    return {
      table_name: '',
      table_fields: {},
      table_constraint: [],
    };
  },
  methods: {
    fresh_this(tableName) {
      this.table_name = tableName;
      axios.get('/api/sql/fields', { params: { table: tableName } }).then(
        (res) => {
          this.table_fields = res.data;
        },
      );
      axios.get('/api/sql/constraint', { params: { table: tableName } }).then(
        (res) => {
          this.table_constraint = res.data;
        },
      );
    },
  },
  watch: {
    $route(to) {
      this.fresh_this(to.params.table);
    },
  },
};
</script>

<style scoped>

</style>
